package com.ruoyi.web.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.web.api.domain.TChapter;
import com.ruoyi.web.service.ITChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 文章管理Controller
 * 
 * @author ruoyi
 * @date 2023-10-08
 */
@RestController
@RequestMapping("/chapter")
public class TChapterController extends BaseController
{
    @Autowired
    private ITChapterService tChapterService;


    @GetMapping("/listAll")
    public R<List<TChapter>> listAll(TChapter tChapter)
    {
        tChapter.setCcid(1L);
        List<TChapter> list = tChapterService.selectTChapterList(tChapter);
        return R.ok(list);
    }
    /**
     * 查询文章管理列表
     */
    @RequiresPermissions("web:chapter:list")
    @GetMapping("/list")
    public TableDataInfo list(TChapter tChapter)
    {
        startPage();
        List<TChapter> list = tChapterService.selectTChapterList(tChapter);
        return getDataTable(list);
    }

    /**
     * 导出文章管理列表
     */
    @RequiresPermissions("web:chapter:export")
    @Log(title = "文章管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TChapter tChapter)
    {
        List<TChapter> list = tChapterService.selectTChapterList(tChapter);
        ExcelUtil<TChapter> util = new ExcelUtil<TChapter>(TChapter.class);
        util.exportExcel(response, list, "文章管理数据");
    }

    /**
     * 获取文章管理详细信息
     */
    @RequiresPermissions("web:chapter:query")
    @GetMapping(value = "/{cid}")
    public AjaxResult getInfo(@PathVariable("cid") Long cid)
    {
        return success(tChapterService.selectTChapterByCid(cid));
    }

    /**
     * 新增文章管理
     */
    @RequiresPermissions("web:chapter:add")
    @Log(title = "文章管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TChapter tChapter)
    {
        return toAjax(tChapterService.insertTChapter(tChapter));
    }

    /**
     * 修改文章管理
     */
    @RequiresPermissions("web:chapter:edit")
    @Log(title = "文章管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TChapter tChapter)
    {
        return toAjax(tChapterService.updateTChapter(tChapter));
    }

    /**
     * 删除文章管理
     */
    @RequiresPermissions("web:chapter:remove")
    @Log(title = "文章管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cids}")
    public AjaxResult remove(@PathVariable Long[] cids)
    {
        return toAjax(tChapterService.deleteTChapterByCids(cids));
    }
}
